package com.opener.web.spring.i18n;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;

import javax.annotation.PostConstruct;


/**
 * @author baboy
 */
public class MessageSource extends ResourceBundleMessageSource {
	private static Logger logger = LoggerFactory.getLogger(MessageSource.class);
	private static MessageSource instance;
	public static String getMessage(String code, Object... args) {
		try {
			return instance.getMessage(code, args, LocaleContextHolder.getLocale());
		} catch (NoSuchMessageException e) {
			return code;
		}
	}

	@PostConstruct
	public void init(){
		logger.info("MessageSource init");
		instance = this;
	}
}
